package com.filldream.fastboot.web.controller.common;

import com.filldream.fastboot.common.annotation.PassTokenAnnotation;
import com.filldream.fastboot.core.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@AllArgsConstructor
@PassTokenAnnotation
@Api(tags = "文件下载管理")
@RequestMapping(value = "/common/file")
public class DownloadController {

    private UploadService uploadService;

    @GetMapping(value = "/{fileName}")
    @ApiOperation(value = "下载本地文件",notes = "下载本地文件")
    public void downloadLocalFile(HttpServletResponse response, @PathVariable String fileName, Boolean isDownLoad) {
        uploadService.downloadLocalFile(response,fileName,isDownLoad);
    }

    @GetMapping(value = "/view/{fileName}")
    @ApiOperation(value = "预览本地文件",notes = "预览本地文件")
    public void viewFile(HttpServletRequest request, HttpServletResponse response, @PathVariable String fileName) {
        uploadService.downloadLocalFile(response,fileName,true);
    }

}
